import axios from "axios"
import store from '@/store/'
const request = axios.create({
  baseURL: 'http://localhost:3000/api',
  // baseURL: 'http://120.55.13.230:3000/api',
})

// 请求拦截器
// Add a request interceptor
request.interceptors.request.use(function (config) {
  // Do something before request is sent
  const { user } = store.state
  // 如果用户已登录，统一给接口设置 token 信息
  if (user) {
    config.headers.Authentication = `Bearer ${user.token}`
  }
  // 处理完之后一定要把 config 返回，否则请求就会停在这里
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})

export default request